local zhuaya = fk.CreateSkill {
  name = "th_zhuaya",
}

zhuaya:addEffect(fk.EventPhaseEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    local slash = Fk:cloneCard("slash")
    slash.skillName = zhuaya.name
    return player:hasSkill(zhuaya.name) and target and target.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = zhuaya.name,
      prompt = "#th_zhuaya-invoke:" .. target.id
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage{
      from = nil,
      to = player,
      damage = 1,
      skillName = zhuaya.name,
    }
    if player.dead then return end
    local slash = Fk:cloneCard("slash")
    slash.skillName = zhuaya.name
    local default = slash:getAvailableTargets(player, { bypass_distances = true, bypass_times = true })
    if #default == 0 then return end
    local _, dat = room:askToUseActiveSkill(target, {
      skill_name = "#th_zhuaya_slash",
      prompt = "#th_zhuaya-slash:" .. player.id,
      cancelable = false,
      extra_data = {
        skillName = zhuaya.name,
        th_zhuayaUser = player,
        th_zhuayaBanned = table.filter(default, function(to)
          return to:getMark("@@th_zhuaya-round-noclear") ~= 0
        end)
      }
    })
    local targets
    if dat then
      targets = dat.targets
    else
      targets = slash:getDefaultTarget(player, { bypass_distances = true, bypass_times = true })
    end
    for _, to in ipairs(targets) do
      if to:isAlive() then
        room:addPlayerMark(to, "@@th_zhuaya-round-noclear", 1)
      end
    end
    local use = { ---@type UseCardDataSpec
      from = player,
      card = slash,
      tos = targets
    }
    room:useCard(use)
  end
})
zhuaya:addEffect("targetmod", {
  name = "#th_zhuaya_prohibit",
  bypass_distances = function(self, from, _, card)
    return card and card.trueName == "slash" and table.contains(card.skillNames, zhuaya.name)
  end
})

Fk:loadTranslationTable{
  ["th_zhuaya"] = "爪牙",
  [":th_zhuaya"] = "一名角色出牌阶段结束时，你可以受到1点伤害，视为使用一张由其指定目标（不能是本轮以此法选择过的角色）的无距离限制的【杀】。",

  ["#th_zhuaya-invoke"] = "爪牙：你可以受到1点伤害，视为使用一张由 %src 指定目标的无距离限制的【杀】",
  ["#th_zhuaya-slash"] = "爪牙：你须为 %src 的【杀】（无距离限制）指定目标",

  ["@@th_zhuaya-round-noclear"] = "爪牙",
}

return zhuaya